<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@page import="db.ItemStore"%>
<%@page import="model.AttributeModel"%>
<%@page import="db.Item"%>
<%@page import="java.util.List"%>
<%@page import="model.SearchForm"%>
<html>
<head>
<%@ include file="style.jsp" %>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Toote laoseisu otsing</title>
</head>
<body>
<%@ include file="logout.jsp" %>
	<h3>Toote laoseisu otsing</h3>
	
	<form action="" method="POST">
		<table>
		<tr><td>Nimetus</td><td><input type="text" name="name" 
		<%if(request.getAttribute("name") != null){
		    out.print("value='"+request.getAttribute("name").toString()+"'");
		} %>/></td></tr>
		</table>
		<input type="submit" value="Otsi" class="button"/>
	</form>
	<div>
		<%
		    if (request.getAttribute("items") != null) {
				List<ItemStore> items = (List<ItemStore>) request.getAttribute("items");
				if (items != null && items.size() > 0) {
		%>
		<table id="quantityTable">
			<thead>
				<tr>
					<th>ID</th>
					<th>Nimetus</th>
					<th>Ladu</th>
					<th>Kogus laos</th>
				</tr>
			</thead>
			<tbody>			
			<%
			int i = 0;
			for(ItemStore item : items){
				i++;
				if(i%2 == 0){
					out.println("<tr class='alt'>");
				}else{
					out.println("<tr>");
				}
			    
			    out.println("<td>"+item.getItem().getItem()+"</td>");
			    out.println("<td>"+item.getItem().getName()+"</td>");
			    out.println("<td>"+item.getStore().getName()+"</td>");
			    out.println("<td>"+getValue(item.getItemCount())+" "+item.getItem().getUnitType().getTypeName()+"</td>");
			    out.println("</tr>");
			} %>
			</tbody>
		</table>
		<%
		    	}else{
				out.println("<p class='error'>Sellist toodet pole laos");
			    }
		    }
		%>
	</div>
</body>
<%! private String getValue(Object o){
    if(o != null){
		return o.toString();
    }else{
		return "";
    }
}%>